package com.wzw.shoppingcart.context;

import com.wzw.shoppingcart.service.DiscountPromotionService;
import com.wzw.shoppingcart.service.impl.AnotherDiscountServiceImpl;
import com.wzw.shoppingcart.service.impl.GiftDiscountServiceImplDiscount;
import com.wzw.shoppingcart.service.impl.GlobalDiscountServiceImplDiscount;
import com.wzw.shoppingcart.service.impl.SpecifyDiscountServiceImplDiscount;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import static com.wzw.shoppingcart.constant.Constant.*;

/**
 *@author wzw
 * 2023/4/16
 */
@Component
public class PromotionContext {

    final Map<String, DiscountPromotionService> discountServices = new ConcurrentHashMap<>();

    @Autowired
    public PromotionContext(GlobalDiscountServiceImplDiscount globalDiscountService,
                            SpecifyDiscountServiceImplDiscount specifyDiscountService,
                            AnotherDiscountServiceImpl anotherDiscountService,
                            GiftDiscountServiceImplDiscount giftDiscountService) {
        discountServices.put(GLOBAL_DISCOUNT, globalDiscountService);
        discountServices.put(PRODUCT_DISCOUNT, specifyDiscountService);
        discountServices.put(ANOTHER_DISCOUNT,anotherDiscountService);
        discountServices.put(GIFT_BUY_DISCOUNT,giftDiscountService);
    }

    public DiscountPromotionService getPromotionService(String discountType) {
        return discountServices.get(discountType);
    }
}
